home *** CD-ROM | disk | FTP | other *** search
- Path: news.ov.com!news
- From: glenn@ov.com (Fletcher.Glenn@ov.com)
- Newsgroups: comp.lang.c
- Subject: Re: Generating pointer to struct from string
- Date: 28 Feb 1996 23:51:14 GMT
- Organization: OpenVision
- Message-ID: <4h2ppi$6pb@spanky.pls.ov.com>
- References: <4grk4g$hep@fmsu03.fm.intel.com>
- Reply-To: glenn@ov.com
- NNTP-Posting-Host: foghorn.pls.ov.com
-
- In article hep@fmsu03.fm.intel.com, vdalvi@mcd.intel.com (Vishram Dalvi) writes:
- >Hello,
- >
- >Say I have 3 structs aaa, bbb and ccc of type foo:
- >
- >struct foo {
- > int flag;
- > char name[30]
- >} aaa, bbb, ccc;
- >
- >I assign some values to the data members of all 3 structs. Now I prompt the
- >user for the name of one of these structs. I read in the user entry into a
- >char array. Assume that the user entered "aaa". How can I generate a pointer
- >to the struct "aaa" from the user entry?
- >I do not want a switch/case table (if user entered "aaa", access members of
- >"aaa", if user entered "bbb"...).
- >How do I cast a string into a struct address??
- >Thanks in advance,
- >
- >Vishram Dalvi
- >(vdalvi@mcd.intel.com)
- >
-
-
- At run time, all labels are converted into memory locations. There is no
- relationship to the structure name (except through the symbol table [if present],
- but the symbol table is *very* implementation dependent).
-
- My best suggestion is to make a lookup table consisting of name strings and
- appropriate pointers. Thus you can search through the table looking for a
- string match.
-
- Fletcher.Glenn@ov.com
-
-
-